package com.jianqiao.information.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianqiao.information.information.domain.ArticlesEntity;
import com.jianqiao.information.information.domain.vo.ArticlesDetailVo;
import com.jianqiao.information.information.mapper.ArticlesMapper;
import com.jianqiao.information.information.service.ArticlesService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * author: cyx
 * create: 2024/7/15 15:47
 **/
@Service
public class ArticlesServiceImpl extends ServiceImpl<ArticlesMapper, ArticlesEntity> implements ArticlesService {

    @Autowired
    private ArticlesMapper articlesMapper;

    @Override
    public ArticlesDetailVo selectArticleDetail(String id) {
        ArticlesDetailVo articlesDetailVo = articlesMapper.selectArticleDetail(id);
        return articlesDetailVo;
    }

    @Override
    public PageInfo<ArticlesEntity> selectArticlesList(Map<String, Object> param) {
        int pageNum = Integer.parseInt(param.get("pageNum").toString());
        int pageSize = Integer.parseInt(param.get("pageSize").toString());

        PageHelper.startPage(pageNum ,pageSize);
        LambdaQueryWrapper<ArticlesEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(ArticlesEntity::getCreateTime).eq(ArticlesEntity::getIsPublish ,"true")
                .eq(ArticlesEntity::getDelFlag ,1);
        Object sortId = param.get("sortId");
        if (!"".equals(sortId)){
            queryWrapper.eq(ArticlesEntity::getSortId ,param.get("sortId"));
        }
        List<ArticlesEntity> articlesList = articlesMapper.selectList(queryWrapper);
        PageInfo<ArticlesEntity> articlesEntityPageInfo = new PageInfo<>(articlesList);
        return articlesEntityPageInfo;
    }
}